# -*- coding: utf-8 -*-
from seekfree import GPIO

def exti_handler(self):
    global flag
    flag = 1

GPIO.help()                             # 模块使用说明

pinpg1 = GPIO(0x61, 0, 1)               # G3 输入 上拉
pinpg2 = GPIO(0x62, 0, 1)               # G3 输入 上拉
pinpg3 = GPIO(0x63, 0, 1)               # G3 输入 上拉
pinph2 = GPIO(0x72, 1, 1)               # H2 输出 推完输出高
pinpb13 = GPIO(0x1D, 1, 1)              # B13 输出 推完输出高

pinpg1.interrupt(exti_handler, 1)
pinpg2.info()                           # 模块参数输出

flag = 0
num = 0

while 1:
    if pinpg2.value() == 0:             # 按下按键 G2
        pinph2.low()                    # 亮核心板 H2 LED 灯
    else :                              # 松开按键 G2
        pinph2.high()                   # 灭核心板 H2 LED 灯

    if flag:
        print("Exti interrupt.")
        flag = 0

    if pinpg3.value() == 0:             # 按下按键 G3
        print("Exti GPIO test program.\n")
        pinpb13.high()                  # 灭核心板 B13 LED 灯
        break                           # 退出测试程序 （如果接下来要运行其他代码请先退出本测试程序）

    num += 1
    if num >= 0xfff:
        num = 0
        pinpb13.toggle()                # 翻转 B13 亮灭 LED 灯
